package com.whq.thrift.api.web.admin.service.requestlog.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.whq.thrift.api.common.spring.datasource.DataSourceContextHolder;
import com.whq.thrift.api.web.admin.db.requestlog.RequestLog;
import com.whq.thrift.api.web.admin.db.requestlog.RequestLogMapper;
import com.whq.thrift.api.web.admin.service.requestlog.RequestLogService;
import com.whq.thrift.api.web.admin.util.DateFormatUtil;

@Service
public class RequestLogServiceImpl implements RequestLogService{
	
	@Autowired
	RequestLogMapper requestLogMapper;

	public List<RequestLog> findRecordsByMap(Map<String, Object> whereParams,
			int beginIndex, int maxCount) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		whereParams.put("beginIndex", beginIndex);
		whereParams.put("maxCount", maxCount);
		return this.requestLogMapper.findRecordsByMap(whereParams);
	}

	public int findRecordCount(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		return this.requestLogMapper.findRecordsCount(whereParams);
	}

	public RequestLog findRecordById(String id, String time) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		RequestLog requestLog = new RequestLog();
		requestLog.setTime(DateFormatUtil.formatStringToFullDate(time));
		int tableSeq = requestLog.getTableSeq();
		requestLog = null;
		return this.requestLogMapper.getRecordByKey(tableSeq, id);
	}

	public List<RequestLog> statByMethodCode(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		return this.requestLogMapper.statByMethodCode(whereParams);
	}

	public List<RequestLog> statByCode(Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		return this.requestLogMapper.statByCode(whereParams);
	}

	public List<RequestLog> queryGateWayCostTimeCountData(
			Map<String, Object> whereParams) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		if (whereParams == null) {
			whereParams = new HashMap<String, Object>(0);
		}
		return this.requestLogMapper.queryGateWayCostTimeCountData(whereParams);
	}

	public void replaceStatDateApiData(int tableSeq, String statDay, String startTime, String endTime) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		this.requestLogMapper.replaceStatDateApiData(tableSeq, statDay, startTime, endTime);
	}

	public void replaceStatHourApiData(int tableSeq, String statDay, String startTime, String endTime, int statHour) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		this.requestLogMapper.replaceStatHourApiData(tableSeq, statDay, startTime, endTime, statHour);
	}

	public void delDataApiData(String thresholdTime) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		this.requestLogMapper.delDataApiData(thresholdTime);
	}

	public void delHourApiData(String thresholdTime) {
		DataSourceContextHolder.set("dataSourceRequestLog");
		this.requestLogMapper.delHourApiData(thresholdTime);
	}

//	public void replaceStatDatePhoneData(int tableSeq, String statDay, String startTime, String endTime) {
//		DataSourceContextHolder.set("dataSourceRequestLog");
//		this.requestLogMapper.replaceStatDatePhoneData(tableSeq, statDay, startTime, endTime);
//	}

//	public void delDatePhoneData(String thresholdTime) {
//		DataSourceContextHolder.set("dataSourceRequestLog");
//		this.requestLogMapper.delDatePhoneData(thresholdTime);
//	}

}
